package com.common.www.controller;

import org.springframework.boot.base.jpa.service.IBaseService;
import com.common.www.bean.entity.Result;
import com.common.www.bean.entity.TestDatabase;
import com.common.www.controller.base.DefaultReadController;
import com.common.www.service.TestDatabaseService;
import com.common.www.service.file.FileService;
import com.common.www.service.redis.RedisTemplateService;
import com.common.www.utils.R;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.awt.Robot;
import java.awt.event.InputEvent;
import java.util.HashMap;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@CrossOrigin()
@Api(tags = "API 测试接口")
@RequestMapping(value = {"/api/test/"})
public class TestController extends DefaultReadController<TestDatabase, Long> {

    @Autowired
    TestDatabaseService testDatabaseService;
    @Autowired
    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
    @Autowired
    RedisTemplateService redisTemplateService;
    @Autowired
    FileService fileService;

    @Value("${ipAddress}")
    private String ipAddress;

    @Override
    protected IBaseService getService() {
        return testDatabaseService;
    }


    @ApiOperation("测试模拟鼠标点击")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/simulateMouse", method = RequestMethod.POST)
    public Result simulateMouse() {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
//            Process p = Runtime.getRuntime().exec("E:\\Program Files (x86)\\Tencent\\TIM\\Bin\\QQScLauncher.exe");
//            p.waitFor();

            // 休息5秒钟
            Thread.currentThread().sleep(2000);

            Robot robot = new Robot();
            //设置Robot产生一个动作后的休眠时间,否则执行过快
            robot.setAutoDelay(1000);
            //移动鼠标
            robot.mouseMove(500, 500);
            // 点击鼠标左键
            System.out.println("单击");
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);

            resultMap.put("code", true);
            resultMap.put("data", "[通信 - 打开控制台程序成功]！");
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("code", false);
            resultMap.put("data", "[通信 - 打开控制台程序失败]！");
        }

        return R.ok();
    }

    @ApiOperation("网页html测试查询")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/testGetHtml", method = RequestMethod.POST)
    public Result testGetHtml() {
        String content = "<h1 style=\"text-align: center;\"><strong>发多少发多少发送到发少</strong></h1><p style=\"text-align: center;\"><img class=\"match-width\" src=\"http://testqiniu.hulkcar.com/test2.png\" data-local=\"blob:http://localhost:8083/c874bd49-2eb8-4d1d-a96a-04041088f539\" alt=\"图像\">的兴奋地说发多少发送到发多少发多少发多少</p><ol><li style=\"text-align: left;\">fsd fsd fsd</li><li style=\"text-align: left;\">f sd</li><li style=\"text-align: left;\">f ds</li><li style=\"text-align: left;\"> fds</li><li style=\"text-align: left;\"> faasd</li><li style=\"text-align: left;\"> 发多少f手动f手动f手动f手动</li><li style=\"text-align: left;\">发多少分发多少</li><li style=\"text-align: left;\">发多少发f 发多少发多少</li><li style=\"text-align: left;\"> 第三方sd 发多少f但是</li></ol><p style=\"text-align: center;\"><br></p> ";
        return R.ok(content);
    }

}
